package com.yonyou.isv.demo.openapi.api.tax.entity.output_invoice;

import com.google.gson.GsonBuilder;

import java.util.*;

/**
 * 销项开票构造参数
 * */
public class InvoiceBuildParam {

    /**
     * 未开票查询
     */
    public static Map<String, Object> result() {
        Map<String, Object> paramsMap = new HashMap<String, Object>();
        //发票代码
        paramsMap.put("lyid", "1");
        //发票号码
        paramsMap.put("djqqlsh", "23770399");
        paramsMap.put("orgCode", "20160914001");
        paramsMap.put("pageNum", "1");
        paramsMap.put("orgSize", "20160914001");

        return paramsMap;
    }


    /**
     * 构造 开票申请删除 表单数据
     */
    public static String buildInvoiceApplyDelParam() {
        List<Object> datas = new ArrayList<>();
        Map<String, String> requestdatas = new HashMap();
        requestdatas.put("FPQQLSH", "26671033302026544154");//发票请求流水号  必填
        requestdatas.put("XSF_NSRSBH", "111222333456111");//销售方纳税人识别号 必填
        datas.add(requestdatas);
        return new GsonBuilder().create().toJson(datas);
    }


    /**
     * 开票申请审核通过
     */
    public static String issue() {
        List<Object> datas = new ArrayList<Object>();
        Map<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("FPQQLSH", "07646104238312188144");//必须为待开票的发票申请流水号
        paramsMap.put("XSF_NSRSBH", "111222333456111");
        paramsMap.put("JSHJ", 117);
        datas.add(paramsMap);
        return new GsonBuilder().create().toJson(datas);
    }


    /**
     * url回掉配置
     */
    public static String buildUrlConfigs(String fpqqlsh) {
        List<Object> datas = new ArrayList<Object>();
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("fpqqlsh", fpqqlsh);
        data.put("url", "http://18z7873y70.eicp.vip/taxcloud/callback");
        datas.add(data);
        GsonBuilder builder = new GsonBuilder();
        return builder.create().toJson(datas);
    }

    /**
     * 构造短信发送信息
     */
    public static String buildSmsConfigs(String fpqqlsh) {
        List<Object> datas = new ArrayList<Object>();
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("fpqqlsh", fpqqlsh);
        data.put("address", "155****3180");
        datas.add(data);
        GsonBuilder builder = new GsonBuilder();
        return builder.create().toJson(datas);
    }

    /**
     * 构造email发送信息
     */
    public static String buildEmailConfigs(String fpqqlsh) {
        List<Object> datas = new ArrayList<Object>();
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("fpqqlsh", fpqqlsh);
        data.put("address", "kw272@yonyou.com");
        datas.add(data);
        GsonBuilder builder = new GsonBuilder();
        return builder.create().toJson(datas);
    }

    /**
     * 构造requestdatas
     */
    public static String buildRequestDatas(String fpqqlsh) {
        List<Object> datas = new ArrayList<Object>();
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("FPQQLSH", fpqqlsh);
        data.put("XSF_NSRSBH", "111222333456111");
        data.put("GMF_MC", "接口测试组织-请勿修改");
        data.put("GMF_NSRSBH", "111222333456111");
        data.put("GMF_DZDH", "广州市花都区红棉大道北16号4楼4B07室 020-61796191");
        data.put("GMF_YHZH", "中国农业银行股份有限公司广州花都名门支行 44087001040011474");
        data.put("FPLX", "1");
        //组织编码
        data.put("ORGCODE", "342423");
        data.put("JSHJ", 117);
        data.put("items", buildItems());

        datas.add(data);
        GsonBuilder builder = new GsonBuilder();
        return builder.create().toJson(datas);
    }

    /**
     * 构造redRequestdatas
     */
    public static String redRequestDatas() {
        List<Object> datas = new ArrayList<Object>();
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("FPQQLSH", "70204347613882104718");
        //蓝色发票代码
        data.put("fpDm", "044007679677");//91110105MA0084MW37
        //蓝色发票号码
        data.put("fpHm", "21427457");
        data.put("JSHJ", 100);
        data.put("items", buildItems());
        //  data.put("ORGCODE", "");//91110105MA0084MW37
        datas.add(data);
        GsonBuilder builder = new GsonBuilder();
        return builder.create().toJson(datas);
    }

    /**
     * 拆分
     *
     * @return
     */
    public static String buildRequestDatasSplit(String fpqqlsh) {
        List<Object> datas = new ArrayList<Object>();
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("FPQQLSH", fpqqlsh);
        data.put("XSF_NSRSBH", "111222333456111");
        data.put("XSF_MC", "销售方名称");
        data.put("XSF_DZDH", "江苏省 无锡市   中国江苏省无锡市江阴市滨江西路");
        data.put("GMF_MC", "接口测试组织-请勿修改");
        data.put("GMF_MC", "接口测试组织-请勿修改");
        data.put("JSHJ", 4000000);
        data.put("items", buildItems());
        datas.add(data);
        GsonBuilder builder = new GsonBuilder();
        return builder.create().toJson(datas);
    }

    /**
     * 构造request发票明细
     * 实际商品信息应和公司对应的编码信息相同
     */
    private static List<Object> buildItems() {
        List<Object> items = new ArrayList<Object>();
        Map<String, Object> data2 = new HashMap<String, Object>();
        Map<String, Object> data1 = new HashMap<String, Object>();
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("XMMC", "POLO衫");//项目名称 必填
        data.put("XMJSHJ", 117);//项目价税合计 必填
        data.put("SL", 0.17);//税率 必填
        data.put("SPBM", "1090625010000000000");//商品的税收分类编码 必填
        //data.put("XMBM", "202020012");//项目编码  如果项目名称为空，会根据项目编码匹配云平台的商品档案
        //data.put("GGXH", "25kg/桶");//规格型号 选填
        //data.put("DW", "千克");//单位 选填
        //data.put("XMSL", 2);//项目数量 选填
        //data.put("SE", -57.52);//税额 选填
        //data.put("FPHXZ", "1");//发票行性质 0正常行 1折扣行 2被折扣行 选填
        //data.put("HH", "1");//行号 选填 有折扣时必输
        items.add(data);

        /*data1.put("XMMC", "POLO衫");
        data1.put("XMJSHJ", 100);
        data1.put("SL", 0.16);
        data1.put("SPBM", "1090625010000000000");
        data1.put("XMBM", "202020012");
        data1.put("GGXH", "25kg/桶");
        data1.put("DW", "千克");
        data1.put("XMSL", 2);
        data1.put("SE", -57.52);
        data1.put("FPHXZ", "2");
        data1.put("HH", "2");
        data1.put("ZKHHH", "1");
        items.add(data1);

        data2.put("XMMC", "饮用水 娃哈哈 Wahaha");
        data2.put("XMJSHJ", 10);
        data2.put("SL", 0.13);
        data2.put("SPBM", "3060101000000000000");
        data2.put("XMBM", "1316927134524661760");
        data2.put("GGXH", "596ml");
        data2.put("DW", "箱");
        data2.put("XMSL", 2);
        data2.put("SE", -57.52);
        items.add(data2);*/
        return items;
    }


    /**
     * 获取发票请求流水号
     * 长度不超过20位，长度在1到20位的字母和数字组合，不可以重复的，不要包含window系统文件名限制的特殊字符
     *
     * @return 发票请求流水号
     */
    public static String buildFpqqlsh() {
        //return "svc20210628141012739";
        StringBuilder rs = new StringBuilder();
        Random random = new Random();
        for(int i=0;i<20;i++){
            rs.append(random.nextInt(9));
        }
        return rs.toString();
    }


    /**
     * 发票作废Requestdatas参数
     */
    public static String buildInvalidRequestdatas() {
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("fpHm", "16138377");//发票号码,必填
        data.put("fpDm", "233005345591");//发票代码,必填
        GsonBuilder builder = new GsonBuilder();
        return builder.create().toJson(data);
    }


}
